//
//  XDToRechargeViewController.m
//  xindailianmeng
//
//  Created by 张东 on 2017/2/28.
//  Copyright © 2017年 xindailianmeng.cn. All rights reserved.
//

#import "XDToRechargeViewController.h"
#import "AFHTTPSessionManager+POST.h"
#import "XDAlertView.h"
#import "XDVerifiedViewController.h"
#import "XDLMMyViewController.h"
#import "SDWebImageManager.h"
#import "ZHRTBasicMethod.h"
#import "XDTopupViewController.h"
#import "XDSetSafePassViewController.h"
#import "XDBindBankCardViewController.h"
#import "ZHRTRequestFailureShowViewOrDetail.h"
#import "XDCheckWithdrawViewController.h"
#import "XDToWithdrawViewController.h"
#import "XDGetCityViewController.h"
#import "XDGetSubBankNameController.h"
@interface XDToRechargeViewController ()

@property (nonatomic, weak) UIView *noCardview;

@property (nonatomic, weak) UIButton *bankleftBtn;

@property (nonatomic, weak) UITextField *bankTf;

@property (nonatomic, weak) UILabel *limitLb;

@property (nonatomic, weak) UITextField *moneyTf;

@property (nonatomic, weak) UIButton *nextBtn;

@property (nonatomic, copy) NSString *bankType;

@property (nonatomic, copy)NSString *bankId;

@property (nonatomic, weak) UIButton *leftItem;


// 提现
// 所在城市
@property (nonatomic, weak) UILabel *cityLb;
// 支行
@property (nonatomic, weak) UILabel *subBranch;
// 银行卡所属银行
@property (nonatomic, weak) UIButton *bank;
// 银行卡卡号
@property (nonatomic, weak) UILabel *bankNo;
// 下一步
@property (nonatomic, weak) UIButton *toWithdrawNext;

@property (nonatomic, copy) NSString *accountProvince;

@property (nonatomic, copy) NSString *bankCode;

@property (nonatomic, copy) NSString *cityCode;

@end

@implementation XDToRechargeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kColorRGB(234, 234, 234);
    NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
    self.title = [df valueForKey:@"toWithdraw"] ? @"提现" : @"充值";
//    viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    UIImage *img = [[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIButton *leftItem = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, img.size.width, img.size.height)];
    [leftItem setBackgroundImage:img forState:UIControlStateNormal];
    [leftItem setBackgroundImage:img forState:UIControlStateHighlighted];
    [leftItem setBackgroundImage:img forState:UIControlStateSelected];
    [leftItem addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.leftItem = leftItem;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftItem];
    
     [self loadData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.leftItem.selected = YES;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hotCityNoti:) name:@"hotCityArr" object:nil];
    //    subCityName
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(subCityNoti:) name:@"subCityName" object:nil];
}

- (void)loadData {
    
     NSDictionary * param = @{@"method":@"myBank"};

    [AFHTTPSessionManager POSTWithParams:param success:^(NSURLSessionDataTask *task, id responseObject) {
    
        if ([responseObject[@"code"] isEqualToString:@"100000"]) {
            /*
             
             
             code = 100000;
             message = "\U64cd\U4f5c\U6210\U529f";
             result =     {
             bankInfo =         {
             bankCardType = "\U501f\U8bb0\U5361";
             bankCode = bocm;
             bankIconUrl = "http://172.16.20.248:6060/zhrtChinaWeb/biz-assets/bankIcon/small/bocm.png";
             bankId = 5;
             bankName = "\U4ea4\U901a\U94f6\U884c";
             bankNumber = "6222 **** **** 2795";
             bankType = 1;
             };
             idNumber = "152************622";
             isBindBank = Y;
             realName = "*\U6da6\U8679";
             };
             type = success;
             }
             
             */
            NSString *bindStatus = responseObject[@"result"][@"isBindBank"];
            if ([bindStatus isEqualToString:@"Y"]) {
                
                NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
                if ([df valueForKey:@"toWithdraw"]) {
                    [self toWithdraw];
                    
                } else {
                    
                [self toRecharge];
                }
                
            } else {
                
                
                [self setNoBindCard];
                
            }
            
       
        } else if ([responseObject[@"code"] isEqualToString:@"100001"]){ // 超时
            
            
        } else {
            
            [ZHRTRequestFailureShowViewOrDetail showViewDetail:responseObject[@"message"] view:self.view];
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}

#pragma mark 提现
// 进入提现界面
- (void)toWithdraw {
    [self setToWithdrawUI];
    [self loadToWithdrawData];
}

- (void)setToWithdrawUI {
    
   UIButton *bank = [self bankNumber];
    self.bank = bank;
//    请选择银行卡所在城市
    UILabel *cityLb = [self createLableWithBtnFrame:CGRectMake(0, CGRectGetMaxY(bank.frame) + 10, kScreenW, 50) btnTitle:@"银行卡所在城市" lableText:@"" tag:100];
     self.cityLb = cityLb;
//    请选择银行卡所在支行
    UILabel *subBranch = [self createLableWithBtnFrame:CGRectMake(0, CGRectGetMaxY(bank.frame) + 70, kScreenW, 50) btnTitle:@"银行卡支行" lableText:@"" tag:101];
    self.subBranch = subBranch;
    
    UIButton *toWithdrawNext = [[UIButton alloc] initWithFrame:CGRectMake((kScreenW - 240) / 2, CGRectGetMaxY(bank.frame) + 158, 240, 40)];
    [toWithdrawNext setImage:[UIImage imageNamed:@"next_fill_hieght"] forState:UIControlStateNormal];
    [toWithdrawNext addTarget:self action:@selector(toWithdrawNextBtn) forControlEvents:UIControlEventTouchUpInside];
    self.toWithdrawNext = toWithdrawNext;
    [self.view addSubview:toWithdrawNext];
}


// 银行卡信息
- (UIButton *)bankNumber {
    
    
    UIButton *backgroundBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 10, kScreenW, 50)];
    [backgroundBtn setBackgroundImage:[UIImage imageNamed:@"textfield-1"] forState:UIControlStateNormal];
    [backgroundBtn setBackgroundImage:[UIImage imageNamed:@"textfield-1"] forState:UIControlStateHighlighted];
    [backgroundBtn setTitle:@"交通银行" forState:UIControlStateNormal];
    [backgroundBtn setImage:[UIImage imageNamed:@"abc"] forState:UIControlStateNormal];
    [backgroundBtn setTitleColor:kColorRGB(102,102,102) forState:UIControlStateNormal];
    backgroundBtn.titleLabel.font = kBaseFont_(14);
    backgroundBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    backgroundBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    backgroundBtn.titleEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
    backgroundBtn.userInteractionEnabled = NO;
    [self.view addSubview:backgroundBtn];
    
    UILabel *cityLb = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenW - 15, 50)];
    cityLb.text = @"6217********8419";
    cityLb.font = kBaseFont_(16);
    cityLb.textColor = kColorRGB(51, 51, 51);
    cityLb.textAlignment = NSTextAlignmentRight;
    [backgroundBtn addSubview:cityLb];
    self.bankNo = cityLb;
    return backgroundBtn;
}
- (UILabel *)createLableWithBtnFrame:(CGRect)frame btnTitle:(NSString *)btnTitle lableText:(NSString *)lableText  tag:(NSInteger)tag{
    
    UIButton *backgroundBtn = [[UIButton alloc] initWithFrame:frame];
    [backgroundBtn setBackgroundImage:[UIImage imageNamed:@"textfield-1"] forState:UIControlStateNormal];
    [backgroundBtn setBackgroundImage:[UIImage imageNamed:@"textfield-1"] forState:UIControlStateHighlighted];
    [backgroundBtn setTitle:btnTitle forState:UIControlStateNormal];
    [backgroundBtn setImage:[UIImage imageNamed:@"nextInd"] forState:UIControlStateNormal];
    [backgroundBtn setImage:[UIImage imageNamed:@"nextInd"] forState:UIControlStateHighlighted];
    [backgroundBtn setTitleColor:kColorRGB(102,102,102) forState:UIControlStateNormal];
    backgroundBtn.titleLabel.font = kBaseFont_(14);
    backgroundBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 15);
    backgroundBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    backgroundBtn.imageEdgeInsets = UIEdgeInsetsMake(0, kScreenW - 30 - 6, 0, 0);
    backgroundBtn.titleEdgeInsets = UIEdgeInsetsMake(0,-6, 0, 0);
    [backgroundBtn addTarget:self action:@selector(backgroundBtn:) forControlEvents:UIControlEventTouchUpInside];
    backgroundBtn.tag = tag;
    [self.view addSubview:backgroundBtn];
    
    UILabel *cityLb = [[UILabel alloc] initWithFrame:CGRectMake(150, 0, kScreenW - 180, 50)];
    cityLb.text = lableText;
    cityLb.font = kBaseFont_(16);
    cityLb.textColor = kColorRGB(51, 51, 51);
    cityLb.textAlignment = NSTextAlignmentRight;
    [backgroundBtn addSubview:cityLb];
    return cityLb;
}



- (void)loadToWithdrawData {
    
    NSDictionary * param = @{@"method":@"toWithdrawAccount"};
    [AFHTTPSessionManager POSTWithParams:param success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if ([responseObject[@"code"] isEqualToString:@"100000"]) {
            /*
             
             
             
             
           */
            NSDictionary *dic = responseObject[@"result"][@"bankInfo"];
            
            [[SDWebImageManager sharedManager] downloadImageWithURL:dic[@"bankIconUrl"] options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                // 银行卡所属银行
                [self.bank setTitle:dic[@"bankName"] forState:UIControlStateNormal];
                
                [self.bank setImage:[self OriginImage:image scaleToSize:CGSizeMake(16.0, 16.0)] forState:UIControlStateNormal];
            }];
//            accountCity = "<null>";
//            accountProvince = "<null>";
//            bankCode = boc;
//            bankIconUrl = "http://172.16.20.162:8080/zhrtChinaWeb/biz-assets/bankIcon/small/boc.png";
//            bankId = 61;
//            bankName = "\U4e2d\U56fd\U94f6\U884c";
//            bankNumber = "6217 **** **** 0548";
//            brachName = "<null>";
//        };
            // 银行卡卡号
            if (![dic[@"accountCity"] isKindOfClass:[NSNull class]]) {
                self.cityLb.text = dic[@"accountCity"];
            }
            self.bankNo.text = dic[@"bankNumber"];
            // 所在城市
            // 省
            if (![dic[@"accountProvince"] isKindOfClass:[NSNull class]]) {
                self.accountProvince = dic[@"accountProvince"];
            }
            self.bankCode = dic[@"bankCode"];
            self.bankType = [dic[@"bankType"] stringValue];
            
            self.bankId = [dic[@"bankId"] stringValue];
            // 支行
            if (![dic[@"brachName"] isKindOfClass:[NSNull class]]) {
                self.subBranch.text = dic[@"brachName"];
            }
            
        } else if ([responseObject[@"code"] isEqualToString:@"100001"]){ // 超时
            
            
        } else {
            
            
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
    
}


- (void)backgroundBtn: (UIButton *)btn {
    
    if (btn.tag == 100) {
        XDGetCityViewController *getCity = [[XDGetCityViewController alloc] init];
        [self.navigationController pushViewController:getCity animated:YES];
    } else if (btn.tag == 101){
        XDGetSubBankNameController *getSubBankName = [[XDGetSubBankNameController alloc] init];
        getSubBankName.cityCode = self.cityCode;
        getSubBankName.bankCode = self.bankCode;
        getSubBankName.bankAccountNo = [self.bankNo.text stringByReplacingOccurrencesOfString:@" " withString:@""] ;
        [self.navigationController pushViewController:getSubBankName animated:YES];
    }
    
}

- (void) toWithdrawNextBtn {
    
    // 提现下一步
    NSString *bankNumber = [[self.bankNo.text stringByReplacingOccurrencesOfString:@" " withString:@""]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    
    NSString *bankName = [[self.bank.titleLabel.text stringByReplacingOccurrencesOfString:@" " withString:@""]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    self.bankCode = self.bankCode ? self.bankCode : @"";
    if ([self.cityLb.text isEqualToString:@"请选择银行卡所在城市"] || self.cityLb.text == nil) {
        [ZHRTRequestFailureShowViewOrDetail showViewDetail:@"请选择银行卡所在城市" view:self.view];
    } else if ([self.subBranch.text isEqualToString:@"请选择银行卡所在支行"] || self.subBranch.text == nil) {
        [ZHRTRequestFailureShowViewOrDetail showViewDetail:@"请选择银行卡所在支行" view:self.view];
        
    } else {

    NSDictionary * param = @{@"method":@"bindBankCard",@"bankNumber":bankNumber,@"bankCode":self.bankCode,@"bindType":@"2",@"bankName":bankName,@"accountProvince":self.accountProvince,@"accountCity":self.cityLb.text,@"brachName":self.subBranch.text,@"bankId":self.bankId };
    [AFHTTPSessionManager POSTWithParams:param success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([responseObject[@"code"] isEqualToString:@"100000"]) {
         
            XDCheckWithdrawViewController *checkWithdraw = [[XDCheckWithdrawViewController alloc] init];
            checkWithdraw.available = [responseObject[@"result"][@"available"] stringValue];
            [self.navigationController pushViewController:checkWithdraw animated:YES];
        
        
        } else if ([responseObject[@"code"] isEqualToString:@"100001"]){ // 超时
            
            
        } else {
            
            [ZHRTRequestFailureShowViewOrDetail showViewDetail:responseObject[@"message"] view:self.view];
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
        
    }

}

- (void)hotCityNoti:(NSNotification *)noti {
    
    self.cityLb.text = noti.userInfo[@"city"];
    self.cityCode = noti.userInfo[@"cityCode"];
    self.accountProvince = noti.userInfo[@"province"];
    
}
- (void)subCityNoti:(NSNotification *)noti {
    
    self.subBranch.text = noti.userInfo[@"subBankName"];
    self.cityCode = noti.userInfo[@"cityCode"];
}

#pragma mark 充值
// 进入充值界面
- (void)toRecharge {
    
    [self setBindBankCard];
    [self loadBindBankCardData];
    
}

- (void)loadBindBankCardData {
    
    NSDictionary * param = @{@"method":@"toRecharge"};
    [AFHTTPSessionManager POSTWithParams:param success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if ([responseObject[@"code"] isEqualToString:@"100000"]) {
            /*
             
             
             code = 100000;
             message = "\U64cd\U4f5c\U6210\U529f";
             result =     {
             bankCode = bocm;
             bankIconUrl = "http://172.16.20.248:6060/zhrtChinaWeb/biz-assets/bankIcon/small/bocm.png";
             bankId = 5;
             bankLimit = "\U5355\U7b1420\U4e07/\U5355\U65e550\U4e07";
             bankName = "\U4ea4\U901a\U94f6\U884c";
             bankNumber = "6222**** ****2795";
             bankType = 1;
             mobile = 15600803605;
             };
             type = success;             */
            NSDictionary *dic = responseObject[@"result"];
            
                [[SDWebImageManager sharedManager] downloadImageWithURL:dic[@"bankIconUrl"] options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                    [self.bankleftBtn setTitle:dic[@"bankName"] forState:UIControlStateNormal];
                    
                    [self.bankleftBtn setImage:[self OriginImage:image scaleToSize:CGSizeMake(20.0, 20.0)] forState:UIControlStateNormal];
                }];
                
                self.bankTf.text = dic[@"bankNumber"];
                self.limitLb.text = dic[@"bankLimit"];
                self.bankType = [dic[@"bankType"] stringValue];
            
            self.bankId = [dic[@"bankId"] stringValue];
            
        } else if ([responseObject[@"code"] isEqualToString:@"100001"]){ // 超时
            
            
        } else {
            
            
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}


- (void)setBindBankCard {
    
    
    UITextField *bankTf = [self createTextFieldWithFrame:CGRectMake(0, 10, kScreenW, 50) textFont:kBaseFont_(16) textColor:kColorRGB(51, 51, 51) placeholder:nil placeholderFont:nil leftTitle:@"农业银行" delegate:self inView:self.view tag:100 style:1 image:@"abc"];
    bankTf.userInteractionEnabled = NO;
    self.bankTf = bankTf;
    
    UILabel *limitLb = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(bankTf.frame), kScreenW - 15, 40)];
    limitLb.text = @"单笔2万，单日一万";
    limitLb.textAlignment =NSTextAlignmentRight;
    limitLb.font = kBaseFont_(13);
    limitLb.textColor = kColorRGB(102, 102, 102);
    self.limitLb = limitLb;
    [self.view addSubview:limitLb];
    
    UITextField *moneyTf = [self createTextFieldWithFrame:CGRectMake(0, CGRectGetMaxY(limitLb.frame), kScreenW, 50) textFont:kBaseFont_(16) textColor:kColorRGB(51, 51, 51) placeholder:@"充值金额需大于100" placeholderFont:kBaseFont_(13) leftTitle:@"充值金额" delegate:self inView:self.view tag:101 style:0 image:nil];
    self.moneyTf = moneyTf;
    
    UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake((kScreenW - 240) / 2, CGRectGetMaxY(moneyTf.frame) + 38, 240, 40)];
    [nextBtn setImage:[UIImage imageNamed:@"next_fill_nor"] forState:UIControlStateDisabled];
    nextBtn.enabled = NO;
    [nextBtn setImage:[UIImage imageNamed:@"next_fill_hieght"] forState:UIControlStateNormal];
    [nextBtn addTarget:self action:@selector(nextBtnClick) forControlEvents:UIControlEventTouchUpInside];
    self.nextBtn = nextBtn;
    [self.view addSubview:nextBtn];

}



- (UITextField *)createTextFieldWithFrame:(CGRect)frame textFont:(UIFont *)textFont textColor:(UIColor *)textColor placeholder:(NSString *)placeholder placeholderFont:(UIFont *)placeholderFont leftTitle:(NSString *)leftTitle delegate:(id)obj inView:(UIView *)inView tag:(NSInteger)tag style:(NSInteger)style image:(NSString *)image{
    
    UITextField *textField = [[UITextField alloc] initWithFrame:frame];
    textField.background = [UIImage imageNamed:@"textfield-1"];
    textField.textAlignment = NSTextAlignmentRight;
    textField.textColor =  textColor;
    textField.font = textFont;
    textField.tag = tag;
    
    textField.attributedPlaceholder = [self textFieldAttributedPlaceholderWith:textField placeholder:placeholder placeholderFont:placeholderFont];
    if (style == 0) {
        UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 1, 120, 48)];
        leftView.backgroundColor = [UIColor whiteColor];
        
        UILabel *nameLb = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 120, 48)];
        nameLb.text = leftTitle;
        nameLb.textColor = kColorRGB(102,102,102);
        nameLb.font = kBaseFont_(14);
        nameLb.textAlignment = NSTextAlignmentLeft;
        [leftView addSubview:nameLb];
        textField.leftView = leftView;
        
        UILabel *unitLb = [[UILabel alloc] initWithFrame:CGRectMake(0, 1, 31, 48)];
        unitLb.text = @"元";
        unitLb.textAlignment =NSTextAlignmentLeft;
        unitLb.font = kBaseFont_(16);
        unitLb.textColor = kColorRGB(51, 51, 51);

        textField.rightView = unitLb;
        textField.keyboardType = UIKeyboardTypeNumberPad;
        [textField addTarget:self action:@selector(moneyTfChange:) forControlEvents:UIControlEventEditingChanged];
    } else if (style == 1) {
        
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 1, 150, 48)];
        btn.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
         btn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [btn setTitleColor:kColorRGB(102,102,102) forState:UIControlStateNormal];
        btn.titleLabel.font = kBaseFont_(14);
        [btn setTitle:leftTitle forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
        btn.userInteractionEnabled = NO;
        self.bankleftBtn = btn;
        textField.leftView = btn;
        textField.rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 1, 15, 48)];
        
    }
    
    textField.leftViewMode = UITextFieldViewModeAlways;
    textField.rightViewMode = UITextFieldViewModeAlways;
    
    [inView addSubview:textField];
    return textField;
}

//修改UITextField的placeholder字体并垂直居中
- (NSAttributedString *)textFieldAttributedPlaceholderWith:(UITextField *)textField placeholder:(NSString *)placeholder placeholderFont:(UIFont *)placeholderFont  {
    if (placeholder) {
        NSMutableParagraphStyle *style = [textField.defaultTextAttributes[NSParagraphStyleAttributeName] mutableCopy];
        style.minimumLineHeight = textField.font.lineHeight - (textField.font.lineHeight - placeholderFont.lineHeight) / 2.0;
        NSAttributedString *attr = [[NSAttributedString alloc] initWithString:placeholder attributes:@{NSFontAttributeName:placeholderFont, NSParagraphStyleAttributeName : style}];
        return attr;
    }
    return nil;
}

#pragma 没有银行卡
- (void)setNoBindCard {

    if (!self.noCardview) {
    
    UIButton *view = [[UIButton alloc] initWithFrame:CGRectMake(0, 10, kScreenW, 50)];
    [view setBackgroundImage:[UIImage imageNamed:@"textfield-1"] forState:UIControlStateNormal];
    view.enabled = NO;
    self.noCardview = view;
    [self.view addSubview:view];

    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(15, 12, 26, 26)];
    img.image = [UIImage imageNamed:@"add"];
    [view addSubview:img];
    
    
    UILabel *titleLb = [[UILabel alloc] initWithFrame:CGRectMake(45, 0, 200, 50)];
    titleLb.text = @"您还未绑定银行卡";
    titleLb.textColor = kColorRGB(51, 51, 51);
    titleLb.font = kBaseFont_(14);
    titleLb.textAlignment = NSTextAlignmentLeft;
    [view addSubview:titleLb];
    
    UIImageView *nextImg = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenW - 22, 19, 6, 12)];
    nextImg.image = [UIImage imageNamed:@"nextInd"];
    [view addSubview:nextImg];
        
    }
    
//
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
                if (self.leftItem.selected) {
            XDAlertView *alertView = [[XDAlertView alloc] initWithTitle:@"未绑卡" message:@"您还未绑定银行卡,无法充值" sureBtn:@"立即绑卡" cancleBtn:@"暂不绑卡"];
            alertView.resultIndex = ^(NSInteger index){
                
                if (index == 1) {
                    
                    [self toMakeMoney];
                    
                } else {
                    
                    [self.navigationController popToRootViewControllerAnimated:YES];
                }
            };
            
            [alertView showXLAlertView];
                    }
        });
    
}

- (void)toMakeMoney {
    
    
    NSDictionary * param = @{@"method":@"getAccountStatus"};
    
    [AFHTTPSessionManager POSTWithParams:param success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if ([responseObject[@"code"] isEqualToString:@"100000"]) {
            NSDictionary *dic = responseObject[@"result"];
            NSLog(@"%@", dic[@"verifiedStatus"]);
            if ([dic[@"verifiedStatus"] isEqualToString:@"N"]) {
                
                XDVerifiedViewController *verified = [[XDVerifiedViewController alloc] init];
                
                [self.navigationController pushViewController:verified animated:YES];
            } else if ([dic[@"safePassStatus"] isEqualToString:@"N"]) {
                
                XDSetSafePassViewController *setSafe = [[XDSetSafePassViewController alloc] init];
                [self.navigationController pushViewController:setSafe animated:YES];
                
            } else if ([dic[@"bindStatus"] isEqualToString:@"N"]) {
                
                NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
                if ([df valueForKey:@"toWithdraw"]) {
                    XDToWithdrawViewController *toWithdraw = [[XDToWithdrawViewController alloc] init];
                    [self.navigationController pushViewController:toWithdraw animated:YES];
                } else {
                    
                    XDBindBankCardViewController *bindBankCard = [[XDBindBankCardViewController alloc] init];
                    [self.navigationController pushViewController:bindBankCard animated:YES];
                }
                
            }
            
        }else {
            
            [ZHRTRequestFailureShowViewOrDetail showViewDetail:responseObject[@"message"] view:self.view];
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}


-(UIImage*)OriginImage:(UIImage *)image scaleToSize:(CGSize)size{
    // 创建一个bitmap的context
    // 并把它设置成为当前正在使用的context
    //Determine whether the screen is retina
    if([[UIScreen mainScreen] scale] == 2.0){
        
        UIGraphicsBeginImageContextWithOptions(size, NO, 2.0);
    }else{
        UIGraphicsBeginImageContext(size);
    }
    // 绘制改变大小的图片
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    // 从当前context中创建一个改变大小后的图片
    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();        // 使当前的context出堆栈
    UIGraphicsEndImageContext();        // 返回新的改变大小后的图片
    return scaledImage;
}

- (void)moneyTfChange: (UITextField *)moneyTf {
    
    if (moneyTf == self.moneyTf) {
        
        if (moneyTf.text.length > 2 && [self.bankType isEqualToString:@"1"]) {
            
            self.nextBtn.enabled = YES;
            
        }
      
//        限定充值金额
        else if(moneyTf.text.length > 0 && ![self.bankType isEqualToString:@"1"]) {
            
            self.nextBtn.enabled = YES;
            
        }
        else {
            self.nextBtn.enabled = NO;
        }
        if (moneyTf.text.length > 0) {
            
            NSMutableAttributedString *moneyStr = [self setBalance:moneyTf.text];
            self.moneyTf.attributedText = moneyStr;
        }
    }
}

-(NSMutableAttributedString *)setBalance:(NSString *)balance{
//    if (balance == nil) {
//        balance = @"0";
//    }
    NSString *newBalance = [balance stringByReplacingOccurrencesOfString:@"," withString:@""];
    NSNumberFormatter *formatter = [NSNumberFormatter new];
    [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
    
    NSString *formattedBalance = [formatter stringFromNumber:[NSNumber numberWithInteger:[newBalance integerValue]]];
    
    NSMutableAttributedString *vAttrString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@", formattedBalance] attributes:nil];
    
//    NSLog(@"===---- %@",vAttrString);
    return vAttrString;
}
- (void)nextBtnClick {
    XDTopupViewController *topup = [[XDTopupViewController alloc] init];
    topup.bankId = self.bankId;
    topup.amount = [self.moneyTf.text stringByReplacingOccurrencesOfString:@"," withString:@""];
    [self.navigationController pushViewController:topup animated:YES];
    
    self.bankTf.text = nil;
    self.moneyTf.text = nil;
    self.nextBtn.enabled = NO;
}
- (void)back {
    NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
    [df removeObjectForKey:@"toWithdraw"];
    [df synchronize];
    self.leftItem.selected = NO;
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:@"hotCityArr"];
    //    subCityName
    [[NSNotificationCenter defaultCenter] removeObserver:@"subCityName"];
}
@end
